#include "view_times.h"
#include "display_ctrl.h"
#include "platform_assert.h"
#include "lfs_file_manager_auto.h"
#include "rtc.h"
#include "datetime.h"
#include "blecom.h"
#include "battery_ctrl.h"
#include "sport_his.h"
#include "display_ctrl.h"
#include "display_interface_240x240.h"
#include "datetime.h"
#include "heart_rate_interface.h"
#include "font_mngr.h"
#include "app_trace.h"
#include "weather_ctrl.h"
#include "view_times.h"
#include "math.h"
#include "m_product_test.h"
#include "view_time_0.h"
#include "view_time_1.h"
#include "view_time_2.h"
#include "view_time_3.h"
#include "view_time_4.h"
#include "view_time_5.h"
#include "view_time_6.h"
void view_times_display(int view)
{
    // #warning debug
    if (disp_ctrl.loop_cnt == 0)
    {
        disp_ctrl.auto_refresh_time = 500;
        datetime_t UIdatetime = DateSync();
        disp_ctrl.com_data.u_temp[0] = home_page_type_get();
        disp_ctrl.com_data.u_temp[1] = ble_if_connected();
        disp_ctrl.com_data.u_temp[2] = battery_ctrl_if_charging();
        disp_ctrl.com_data.u_temp[3] = battery_ctrl_get_percent();
        disp_ctrl.com_data.u_temp[4] = UIdatetime.date.month;
        disp_ctrl.com_data.u_temp[5] = UIdatetime.date.day;
        disp_ctrl.com_data.u_temp[6] = UIdatetime.time.hour;
        disp_ctrl.com_data.u_temp[7] = UIdatetime.time.minute;
        disp_ctrl.com_data.u_temp[8] = if_time_hour_system_12();
        disp_ctrl.com_data.u_temp[9] = get_present_week();
        disp_ctrl.com_data.u_temp[10] = sport_get_present_step();
        uint16_t temp16 = get_present_day_minute();
        disp_ctrl.com_data.i_temp[11] = (RTCGetSeconds() % 60) * 6;
        disp_ctrl.com_data.i_temp[12] = (temp16 / 2) % 360; //时针的角度
        disp_ctrl.com_data.i_temp[13] = (temp16 * 6) % 360; //分针的角度
        if (disp_ctrl.com_data.u_temp[8])
        {
            disp_ctrl.com_data.u_temp[8] += (disp_ctrl.com_data.u_temp[6] >= 12); // 1=am,2=pm
            disp_ctrl.com_data.u_temp[6] %= 12;
            if (disp_ctrl.com_data.u_temp[6] == 0)
            {
                disp_ctrl.com_data.u_temp[6] = 12;
            }
        }
    }
#if 0
#warning debug
    view_time_4_display();
#else
    switch (disp_ctrl.com_data.u_temp[0])
    {
#if !defined(TIME_0_SKIP)
    case HOME_PAGE_TYPE_0:
        view_time_0_display();
        break;
#endif
#if !defined(TIME_1_SKIP)
    case HOME_PAGE_TYPE_1:
        view_time_1_display();
        break;
#endif
#if !defined(TIME_2_SKIP)
    case HOME_PAGE_TYPE_2:
        view_time_2_display();
        break;
#endif
#if !defined(TIME_3_SKIP)
    case HOME_PAGE_TYPE_3:
        view_time_3_display();
        break;
#endif
#if !defined(TIME_4_SKIP)
    case HOME_PAGE_TYPE_4:
        view_time_4_display();
        break;
#endif
#if !defined(TIME_5_SKIP)
    case HOME_PAGE_TYPE_5:
        view_time_5_display();
        break;
#endif
#if !defined(TIME_6_SKIP)
    case HOME_PAGE_TYPE_6:
        view_time_6_display();
        break;
#endif
#if !defined(TIME_7_SKIP)
    case HOME_PAGE_TYPE_7:
        view_time_7_display();
        break;
#endif
#if !defined(TIME_8_SKIP)
    case HOME_PAGE_TYPE_8:
        view_time_8_display();
        break;
#endif
#if !defined(TIME_9_SKIP)
    case HOME_PAGE_TYPE_9:
        view_time_9_display();
        break;
#endif
#if !defined(TIME_10_SKIP)
    case HOME_PAGE_TYPE_10:
        view_time_10_display();
        break;
#endif
#if !defined(TIME_11_SKIP)
    case HOME_PAGE_TYPE_11:
        view_time_11_display();
        break;
#endif
#if !defined(TIME_12_SKIP)
    case HOME_PAGE_TYPE_12:
        view_time_12_display();
        break;
#endif
#if !defined(TIME_13_SKIP)
    case HOME_PAGE_TYPE_13:
        view_time_13_display();
        break;
#endif
#if !defined(TIME_14_SKIP)
    case HOME_PAGE_TYPE_14:
        view_time_14_display();
        break;
#endif
#if !defined(TIME_15_SKIP)
    case HOME_PAGE_TYPE_15:
        view_time_15_display();
        break;
#endif
#if !defined(TIME_16_SKIP)
    case HOME_PAGE_TYPE_16:
        view_time_16_display();
        break;
#endif
#if !defined(TIME_17_SKIP)
    case HOME_PAGE_TYPE_17:
        view_time_17_display();
        break;
#endif
#if !defined(TIME_18_SKIP)
    case HOME_PAGE_TYPE_18:
        view_time_18_display();
        break;
#endif
#if !defined(TIME_19_SKIP)
    case HOME_PAGE_TYPE_19:
        view_time_19_display();
        break;
#endif
#if !defined(TIME_20_SKIP)
    case HOME_PAGE_TYPE_20:
        view_time_20_display();
        break;
#endif
#if !defined(TIME_21_SKIP)
    case HOME_PAGE_TYPE_21:
        view_time_21_display();
        break;
#endif
#if !defined(TIME_22_SKIP)
    case HOME_PAGE_TYPE_22:
        view_time_22_display();
        break;
#endif
#if !defined(TIME_23_SKIP)
    case HOME_PAGE_TYPE_23:
        view_time_23_display();
        break;
#endif
    default:
#if defined(DEFAULT_TIME)
        home_page_type_set(DEFAULT_HOME_PAGE);
        DEFAULT_TIME();
#else
        view_time_0_display();
#endif
        break;
        //     case HOME_PAGE_TYPE_0:
        //         view_time_0_display();
        //         break;
        //     case HOME_PAGE_TYPE_1:
        //         view_time_1_display();
        //         break;
        // #if defined(R5MAX_BOARD)
        //     case HOME_PAGE_TYPE_2:
        //         view_time_5_display();
        //         break;
        //     case HOME_PAGE_TYPE_3:
        //         view_time_6_display();
        //         break;
        // #elif defined(R5_BOARD)
        //     case HOME_PAGE_TYPE_2:
        //         view_time_2_display();
        //         break;
        //     case HOME_PAGE_TYPE_3:
        //         view_time_3_display();
        //         break;
        //     case HOME_PAGE_TYPE_4:
        //         view_time_4_display();
        //         break;
        // #endif
        //     default:
        //         view_time_0_display();
        //         break;
    }
#endif
}
view_event_result_t view_times_event(int view, event_param_t const *param)
{
    switch (param->event)
    {
    case event_button_front_long_press:
        if (product_test_state_get() == PRODUCT_TEST_STATE_TEST_ASSEM)
        {
            home_page_type_switch();
            display_show(view_time, DISP_MODE_NORMAL);
        }
        return view_event_result_handled;
    }
    return view_event_result_not_handled;
}
